#include<bits/stdc++.h>
using namespace std;

int a[105][105];

vector<string> split(string s) {
    string t = "";
    vector<string> res;

    for(auto ii : s) {
        if(ii == '+') {
            res.push_back(t);
            t = "";
        } else {
            t += ii;
        }
    }
    res.push_back(t);
    return res;
}

signed main() {

    string s;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }

    getline(cin, s);
    getline(cin, s);
    s = s.substr(1);

    vector<string> t = split(s);
    int sum = 0;
    for(auto st : t) {
        if(st.size() < 2)	continue;
        if(!isupper(st[0]))	continue;
        int y = st[0] - 'A' + 1;
        int x = stoi(st.substr(1));
        if(1 <= x && x <= n && 1 <= y && y <= m)
            sum += a[x][y];
    }
    cout << sum;
    return 0;
}


